//
//  ViewController.m
//  CycleImage
//
//  Created by 徐昊 on 16/8/4.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "ViewController.h"
#import "CustomCollectionViewCell.h"
@interface ViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) NSMutableArray *imageArray;
@property (nonatomic, strong) UICollectionView *collectionView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationController.navigationBar.translucent = NO;
    _imageArray = [NSMutableArray arrayWithObjects:@"1453684724e1c0ab12", @"1453684725fe5d54c7", @"1453684726ef6ecf01", @"145368472336a771f9", @"14536847244844ddae", nil];
    [self handleData];
    [self createCollectionView];
}
- (void)handleData {
    NSString *str1 = [_imageArray firstObject];
    NSString *str2 = [_imageArray lastObject];
    [_imageArray insertObject:str2 atIndex:0];
    [_imageArray addObject:str1];
}
- (void)createCollectionView {
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 150) collectionViewLayout:flow];
    flow.itemSize = CGSizeMake(CGRectGetWidth(self.view.bounds), 150);
    flow.minimumLineSpacing = 0;
    //    flow.minimumInteritemSpacing = 0;
    _collectionView.pagingEnabled = YES;
    _collectionView.showsHorizontalScrollIndicator = NO;
    _collectionView.bounces = NO;
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.contentSize = CGSizeMake(7 * _collectionView.bounds.size.width, 0);
    flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    [self.view addSubview:_collectionView];
    [_collectionView registerNib:[UINib nibWithNibName:@"CustomCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"cell"];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 7;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    NSString *str = [_imageArray objectAtIndex:indexPath.row + 1];
    cell.imageView.image = [UIImage imageNamed:str];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
